#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
int n, q;
char ss[maxn];
int p[maxn];
int st[maxn][21];
int ql[maxn], qr[maxn];
int ans[maxn];
int mlg[maxn];
int rmq(int l, int r){
    int len = mlg[r - l + 1];
    return min(st[l][len], st[r - (1 << len) + 1][len]);
}
struct TreeNode{
    int mx, tag;
};
TreeNode t[maxn << 2];
void pushup(int p){
    t[p].mx = max(t[p << 1].mx, t[p << 1 | 1].mx);
    return ;
}
void lazy(int p, int k){
    t[p].mx += k; t[p].tag += k;
    return ;
}
void pushdown(int p){
    lazy(p << 1, t[p].tag);
    lazy(p << 1 | 1, t[p].tag);
    t[p].tag = 0; return ;
}
void mdf(int p, int pl, int pr, int l, int r, int x){
    if(pl > pr) return ;
    if(pl <= l && r <= pr){
	lazy(p, x); return ;
    }
    int mid = (l + r) >> 1; pushdown(p);
    if(pl <= mid) mdf(p << 1, pl, pr, l, mid, x);
    if(pr > mid) mdf(p << 1 | 1, pl, pr, mid + 1, r, x);
    pushup(p); return ;
}
int que(int p, int pl, int pr, int l, int r){
    if(pl <= l && r <= pr) return t[p].mx;
    int mid = (l + r) >> 1; pushdown(p);
    int res = 0;
    if(pl <= mid) res = max(res, que(p << 1, pl, pr, l, mid));
    if(pr > mid) res = max(res, que(p << 1 | 1, pl, pr, mid + 1, r));
    return res;
}
int top = 0;
int stp[maxn], L[maxn];
vector<pair<int, int>> opt[maxn];
int main(){
    freopen("good.in", "r", stdin);
    freopen("good.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    cin >> (ss + 1);
    p[0] = 0;
    for(int i = 1;i <= n;i++){
	p[i] = p[i - 1] + (ss[i] == '1' ? 1 : -1);
    }
    for(int i = 0;i <= n;i++) st[i][0] = p[i];
    for(int i = 1;(1 << i) <= n + 1;i++){
	for(int j = 0;j + (1 << i) - 1 <= n;j++){
	    st[j][i] = min(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
	}
    }
    mlg[1] = 0;
    for(int i = 2;i <= n + 1;i++){
	mlg[i] = mlg[i - 1] + ((1 << (mlg[i - 1] + 1)) == i);
    }
    for(int i = 1;i <= q;i++){
	cin >> ql[i] >> qr[i];
	opt[ql[i] - 1].emplace_back(qr[i], i);
	ans[i] = p[ql[i] - 1] - rmq(ql[i] - 1, qr[i]);
	// cerr << p[qr[i]] << " " << rmq(ql[i] - 1, qr[i]) << endl;
    }
    // cerr << "ok" << endl;
    stp[++top] = n; L[n] = n;
    for(int i = n - 1;i >= 0;i--){
	// cerr << "?? " << i << endl;
	L[i] = i;
	while(top && p[stp[top]] >= p[i]){
	    mdf(1, stp[top], L[stp[top]], 0, n, p[stp[top]]);
	    L[i] = L[stp[top]]; top--;
	    // cerr << top << endl;
	}
	stp[++top] = i;
	mdf(1, i + 1, L[i], 0, n, -p[i]);
	for(auto pfr : opt[i]){
	    ans[pfr.second] += max(1, que(1, i, pfr.first, 0, n)) -
		que(1, pfr.first, pfr.first, 0, n);
	}
    }
    int pans = 0;
    for(int i = 1;i <= q;i++) pans ^= ans[i];
    cout << pans << '\n';
    cout.flush(); return 0;
}
